package com.cx.thread.message;

import javax.swing.*;
import java.util.LinkedList;

/**
 * @author zhangshuai
 * @version V1.0
 * @Project Java2_26
 * @Package com.cx.thread.message
 * @Description:
 * @Date 2025/5/26 16:43
 */

public class Custom {
    private String name;
    private LinkedList<String> buffer;

    public Custom(String name, LinkedList<String> buffer) {
        this.name = name;
        this.buffer = buffer;
    }

    //消费消息

    public void custom(){
        synchronized (buffer){
            while (true){
               if(buffer.size() <= 0) {
                   System.out.println(name + "等待阻塞");
                   try {
                       buffer.wait();
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }else {
                   System.out.println(name + "消费消息" +buffer.getFirst());
                   buffer.removeFirst();
                   buffer.notifyAll();
               }
            }
        }
    }
}